import request from "@/utils/request";


export function getDeviceList(data) {

	return request({
		url: "/weMini/NotToken/shopDevice/getList",
		method: "get",
		params: data,
		headers: {
			isToken: false
		},
	});
}


export function openDoor(data) {
	return request({
		url: "/weMini/NotToken/shopDevice/openDoor",
		method: "get",
		params: data,
		headers: {
			msg: "开门中,请留意门口"
		}
	});
}

export function doInsert(data) {
	return request({
		url: "/api/v1/shop/device/insert",
		method: "post",
		data,
	});
}

export function doUpdate(data) {
	return request({
		url: "/api/v1/shop/device/update",
		method: "post",
		data,
	});
}

export function doDelete(data) {
	return request({
		url: "/api/v1/shop/device/del",
		method: "post",
		params: data,
	});
}

export function doDeleteAll(data) {
	return request({
		url: "/api/v1/shop/device/delAll",
		method: "post",
		params: data,
	});
}

/**
 * 导出Excel 目前只支持一层参数传递
 * @param params 参数
 * @returns file
 */
export async function doExportExcel(params) {
	let authURL = "/api/v1/shop/device/excel/auth/export";

	let downloadURL = "/api/v1/shop/device/excel/export/";

	// 认证
	const {
		data
	} = await request({
		url: authURL,
		method: "get",
		params: params,
	});

	if (data) {
		// 下载文件
		downloadFileByData(downloadURL + data, params);
	}
}

/**
 * 下载模版
 * @returns file
 */
export async function doDownloadTemplate() {
	let authURL = "/api/v1/shop/device/excel/auth/import-template-export";

	let downloadURL = "/api/v1/shop/device/excel/export/";

	// 认证
	const {
		data
	} = await request({
		url: authURL,
		method: "get",
	});

	if (data) {
		// 下载文件
		downloadFileByData(downloadURL + data, {});
	}
}

/**
 * 导入Excel
 * @returns file
 */
export function doImportExcel(data) {
	return request({
		url: "/api/v1/shop/device/importExcel",
		method: "post",
		// 最长超时时间 3 分钟
		timeout: 180000,
		headers: {
			"Content-Type": "multipart/form-data",
		},
		data,
	});
}